package org.hackystat.devcathlon.ui.page.teams.manage;

import static org.junit.Assert.assertNotNull;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.hackystat.devcathlon.engine.test.DevcathlonTestHelper;
import org.hackystat.devcathlon.ui.DevcathlonApplication;
import org.hackystat.devcathlon.ui.page.login.LoginPage;
import org.hackystat.devcathlon.ui.page.teams.profile.TeamsProfile;
import org.junit.Test;

/**
 * Test classes for the Teams Manage Page.
 *
 * @author John Ly
 *
 */

public class TestTeamsManagePage extends DevcathlonTestHelper { 
     
  private String user = "admin@hackystat.org";
  
  /**
   * Tests the Teams Manage Page for display info.
   * @throws Exception If there is a bug.
   */
  @Test
  public void testTeamsManagePage() throws Exception {
    WicketTester tester = new WicketTester(new DevcathlonApplication());
    makeTeam("Your1stTeam", "admin", "member1", "member2");
    makeTeam("Your2ndTeam", "member1", "admin", "member2");
    
    tester.startPage(TeamsManagePage.class);
    tester.assertRenderedPage(LoginPage.class);    
   
    // Fill out the login form.
    FormTester formTester = tester.newFormTester("loginForm");
    formTester.setValue("user", user);
    formTester.setValue("password", user);
    formTester.submit();
        
    tester.assertRenderedPage(TeamsManagePage.class);
    assertNotNull("wicket ID form found.", tester.getTagByWicketId("StatusLabel"));        
    
    tester.clickLink("TeamsManageLink");
    tester.assertRenderedPage(TeamsManagePage.class);
    
    assertNotNull("wicket ID listview found", tester.getTagByWicketId("TeamsList"));
    
    //Click Teams List links
    tester.clickLink("TeamsList:0:TeamProfileLink");
    tester.assertRenderedPage(TeamsProfile.class);
    
    tester.startPage(TeamsManagePage.class);
    tester.assertRenderedPage(TeamsManagePage.class);
    
    tester.clickLink("TeamsList:0:TeamEditLink");
    tester.assertRenderedPage(TeamsManageEditPage.class);
    
    tester.startPage(TeamsManagePage.class);
    tester.assertRenderedPage(TeamsManagePage.class);
    
    tester.clickLink("TeamsList:0:TeamDeleteLink");
    tester.assertRenderedPage(TeamsManageDeletePage.class);
    
    tester.startPage(TeamsManagePage.class);
    tester.assertRenderedPage(TeamsManagePage.class);    
    
    //Click membership links
    tester.clickLink("MembershipList:0:TeamProfileLink");
    tester.assertRenderedPage(TeamsProfile.class);
    
    tester.startPage(TeamsManagePage.class);
    tester.assertRenderedPage(TeamsManagePage.class);
    
    tester.clickLink("MembershipList:0:TeamResignLink");
    tester.assertRenderedPage(TeamsManageResignPage.class);
        
    
    deleteTeam("Your1stTeam");
  }
  
  
  
  
  
}

